package git.bankview.wl.report;

import java.util.*;
import java.text.*;
import java.io.*;

import laya.semi.process.*;
import git.bankview.sl.report.ReportCommon;
import git.bankview.sl.report.ReportParameter;

import git.bankview.sl.db.*;

import org.apache.log4j.Logger;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;

public class JasperObjectPropertiesGetter
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(JasperObjectPropertiesGetter.class);

	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] params = oCtx.getActivityParameter().split(":");
		String jasperFileName = params[0];
		String jasperPropsName = params[1];
		
		File jasperFile = (File)oCtx.getField(jasperFileName);
		Vector jasperProps = new Vector();

		try
		{
			JasperReport oReport = (JasperReport)JRLoader.loadObject(jasperFile);
			String[] vPropName = oReport.getPropertyNames();
			for (int i = 0; i < vPropName.length; ++i)
			{
				Map pair = new HashMap();
				pair.put("propName", vPropName[i]);
				pair.put("propValue", oReport.getProperty(vPropName[i]));
				jasperProps.addElement(pair);
			}
		
			oCtx.setField(jasperPropsName, jasperProps);
		}
		catch(JRException e)
		{
			log.warn("", e);
			throw new ActivityException(oCtx, "jasperUpload.err.unknowFormat");
		}	
	}
}
